$(document).ready(function() {
	  $('#photo_upload').uploadify({
		    'uploader'  : '/js/uploadify.swf',
		    'script'    : '/js/uploadify.php',
		    'cancelImg' : '/images/cancel.png',
		    'folder'    : '/images/wall',
		 	'onComplete'  : function(event, ID, fileObj, response, data) {   
			  	showimage(response);
		  		},
		    'auto'      : true
	  });
})

function showimage(link){
	var img = "<img src='"+link+"' width=300px />";
	jQuery("#show_photo").html(img);
	jQuery("#photo2").val(link);
//	alert(jQuery("#photo").val());
}
function dpop(id){
	  jQuery("#description_edit").toggle();
}

function edes(){
//	alert('123');
	jQuery.ajax({
		type:"POST",
		url:"/"+jQuery("#user_name").val()+"/info/description",
		data:"description_e="+jQuery("#re_des").val()
	})
	jQuery("#description").html(jQuery("#re_des").val());
	jQuery("#description_edit").css("display","none");
}

function friendrequest(user_id,friend_id){
//	alert(jQuery("#user_name").val());
	jQuery.ajax({
		type:"POST",
		url:"/"+jQuery("#user_name").val()+"/friend/request",
		data:"user_id="+user_id+"&friend_id="+friend_id
	})
	jQuery("#request_button").hide();
	jQuery("#sent").html('request has been sent');
}

function acceptfriend(request_id){
	jQuery.ajax({
		type:"POST",
		url:"/"+jQuery("#user_name").val()+"/friend/acceptfriend",
		data:"request_id="+request_id
	})
	jQuery("#request_result_"+request_id).html("This people is your friend now");
}

function refusefriend(request_id){
	jQuery.ajax({
		type:"POST",
		url:"/"+jQuery("#user_name").val()+"/friend/refusefriend",
		data:"request_id="+request_id
	})
	jQuery("#request_result_"+request_id).html("You refused to be friends with this people");
}

function search(){
	var key = jQuery("#search").val();
//	alert(key);
	if (key){
		jQuery.ajax({
			type:"POST",
			url:"/"+jQuery("#user_name").val()+"/friend/search",
			data:"key="+key,
			success:function(html){
		      jQuery(".friend_list").html(html);
		}
		})
	}
}